Skip to content

[5.2] Strict manifest.json on debug #1168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Oct 15, 2020

Implementing symfony/symfony#38495

Ease development by throwing an exception when an asset is not found in manifest.json.

Throws an exception when an asset is not found in manifest.json
@nicolas-grekas nicolas-grekas changed the base branch from master to main November 19, 2020 12:36
fabpot added a commit to symfony/symfony that referenced this pull request Jul 25, 2021
…missing item (GromNaN)

This PR was merged into the 5.4 branch.

Discussion
----------

[Asset] [DX] Option to make asset manifests strict on missing item

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | symfony/symfony-docs#14414

In all the projects I use a JSON manifest, when an asset is not listed in manifest.json, the asset file is not generated. The current behavior is permissive as it returns the unmodified path of the asset. Which ends with a 404 when the browser tries to load the asset.

With the option `strict_mode: true`, an exception is thrown when we try to use an asset that is not listed in `manifest.json`. Thereby we don't have to check that asset urls are actually working in tests (manual or automated).

**Usage:**
The option `strict_mode` is optional for backward compatibility. Using the `%kernel.debug%` value is safe to flush bugs on dev or test mode but keep the application working on production.

```yaml
# config/packages/assets.yaml

framework:
    assets:
        packages:
            app:
                # Uses a JSON manifest (can be a local path or an url remote file)
                json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
                # Throws an exception when an expected entry is missing in the manifest
                strict_mode: '%kernel.debug%'

```

Todo:
- [x] Documentation symfony/symfony-docs#14414
- [x] Demo symfony/demo#1168
- [x] ~Update recipe ?~

Commits
-------

4cdb921 Option to make asset manifests strict on missing item
@GromNaN GromNaN closed this Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant